<dom-module id="widget-app-item">
    <template>
        <div class$="{{judgeCuration(type)}}"
             amp-appid$="{{appId}}"
             amp-appkey$="{{appKey}}"
             amp-full-screen$="{{showFullScreen}}"
             amp-url$="{{url}}"
             amp-title$="{{title}}"
             amp-img$="{{image}}"
             amp-favorite$="{{favorite}}"
             amp-hasdescription$="{{hasDescription}}"
             amp-haspermission$="{{hasPermission}}"
             amp-descriptionauth$="{{descriptionAuth}}"
             amp-unviewabledescription$="{{unviewableDescription}}"
             amp-type$="{{type}}"
             amp-opening$="{{opening}}"
             amp-maintaining$="{{maintaining}}"
             amp-hashead$="{{isHasHead}}"
             amp-isThirdParty$="{{isThirdParty}}"
             amp-version$="{{version}}"
             amp-category$="{{category}}"
        >
            <content></content>
        </div>
    </template>
    <script>
        Polymer({
            is: 'widget-app-item',
            properties: {
                params: {
                    type: "Object"
                }
            },
            toStr: function(data){
                var str = "";
                if(data === 0 || data === false){
                    str = data.toString();
                }else{
                    str = data ? data.toString() : "";
                }
                return str;
            },
            judgeCuration: function(type) {
                //var curationFlag = type === 1 ? true : false;
                var className = "appFlag";
                if(type == 1){
                    className = "curation appFlag";
                }
                return className;
            },
            getCategoryListStr: function(category){
               var categoryStr = '';
                    if (category) {
                        var categoryLen = category.length;
                        if (categoryLen > 0) {
                            for (var i = 0; i < categoryLen; i++) {
                                if (i !== 0) {
                                    categoryStr += '/' + category[i].categoryName;
                                } else {
                                    categoryStr += category[i].categoryName;
                                }
                            }
                        }
                    }
                    return categoryStr;
            },
            ready: function() {
                var appData = this.params;
                if(appData !=undefined){
                this.appId = appData.appId;
                this.appKey = appData.appKey;
                this.showFullScreen = this.toStr(appData.isOpenInNewTab);
                var _ampUrl ='';
                var isHasHead = '';
                var isThirdParty='';
               if(appData.appPc!= undefined){
                var deployPrefix =  appData.deployPrefix == undefined?'':appData.deployPrefix;
                    _ampUrl = deployPrefix + appData.appPc.entranceUrl;
                    isHasHead = appData.appPc.isHasHead;
                    isThirdParty = appData.appPc.isThirdParty;
                    this.hasDescription = this.toStr(appData.appPc.isEnableDescription);
                    this.descriptionAuth = this.toStr(appData.appPc.descriptionAuth); 
                }else{
                    this.hasDescription = this.toStr(appData.isEnableDescription);
                    this.descriptionAuth = this.toStr(appData.descriptionAuth); 
                }
              /*  this.url = appData.appOpenUrl;*/
                this.url =  "appShow?appId=" + appData.appId;
                this.title = appData.appName;
                this.image = appData.middleIcon;
                this.favorite = this.toStr(appData.favoriteApp);
                this.hasPermission = this.toStr(appData.hasPermission);
              
                this.unviewableDescription = this.toStr(appData.unviewableDescription);
                this.type = appData.type;
                this.opening = this.toStr(appData.opening);
                this.maintaining = this.toStr(appData.maintaining);
                this.isHasHead = isHasHead;
                this.isThirdParty = isThirdParty; 
                this.version = appData.version;
                this.category=this.getCategoryListStr(appData.categoryList);
                }

            }
        });
    </script>
</dom-module>